package com.huilian.iotbox.admin.wap.service.impl;

import com.huilian.iotbox.admin.wap.dao.MerchantPayCompanyDao;
import com.huilian.iotbox.admin.wap.service.MerchantPayCompanyService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.MerchantDto;
import com.huilian.iotbox.data.dto.MerchantPayCompanyDto;
import com.huilian.iotbox.data.enums.PayCompanyEnum;
import com.huilian.iotbox.data.po.Merchant;
import com.huilian.iotbox.data.po.MerchantPayCompany;
import com.huilian.iotbox.data.po.PayCompany;
import com.huilian.iotbox.data.vo.MerchantPayCompanyVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 谢洛涛
 * @date 2021/6/4 16:30
 */
@Service
public class MerchantPayCompanyServiceImpl implements MerchantPayCompanyService {
    @Resource
    private MerchantPayCompanyDao merchantPayCompanyDao;

    @Override
    public Integer addMerchantPayCompany(MerchantPayCompany merchantPayCompany) {
        return merchantPayCompanyDao.addMerchantPayCompany(merchantPayCompany);
    }

    @Override
    public ServerResponse findPayCompany(Merchant merchant) {
        return ServerResponse.createBySuccess(merchantPayCompanyDao.findPayCompany(merchant));
    }


    @Override
    public List<MerchantPayCompanyVo> findMerchantPayCompany(MerchantDto merchantDto) {
        return merchantPayCompanyDao.findMerchantPayCompany(merchantDto);
    }

    @Override
    public ServerResponse findYeahkaOpenSplitStatus(MerchantDto merchantDto) {
        merchantDto.setPayCompanyCode(PayCompanyEnum.YEAHKA.getCode());
        MerchantPayCompany merchantPayCompany = merchantPayCompanyDao.findYeahkaOpenSplitStatus(merchantDto);
        if (merchantPayCompany != null) {
            return ServerResponse.createBySuccess(merchantPayCompany);
        } else {
            return ServerResponse.createByErrorMessage("");
        }
    }

    @Override
    public Integer update(MerchantPayCompanyDto merchantPayCompanyDto) {
        return merchantPayCompanyDao.update(merchantPayCompanyDto);
    }


    @Override
    public ServerResponse findPayCompanyByApplet(String payCompanyCode) {
        Merchant merchant = new Merchant();
        PayCompany payCompany = merchantPayCompanyDao.finOnePayCompany(payCompanyCode);
        List<PayCompany> payCompanyList = merchantPayCompanyDao.findPayCompany(merchant);
        if (payCompany != null && payCompany.getStatus() != Integer.valueOf(PayCompanyEnum.STATUS_ONE.getCode())) {
            payCompanyList.add(payCompany);
        }
        return ServerResponse.createBySuccess(payCompanyList);
    }

    @Override
    public PayCompany finOnePayCompany(String payCompanyCode) {
        return merchantPayCompanyDao.finOnePayCompany(payCompanyCode);
    }
}
